package com.vogue.supplymall.account.shiro.bean;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import org.apache.shiro.crypto.hash.SimpleHash;

/**
 * shiro进行密码加密用的工具<br>
 * 
 * @author 崔岳
 *
 */
@SuppressWarnings("serial")
public class PasswordBean implements Serializable{

	public static String MAP_KEY_USERNAME = "username";
	
	public static String MAP_KEY_PASSWORD = "password";
	
	public static String MAP_KEY_SALT = "salt";
	
	public static String MAP_KEY_NEWPWD = "newpwd";
	
	private String hashAlgorithmName = "md5";
	
	private int hashIterations = 1;

	public String getHashAlgorithmName() {
		return hashAlgorithmName;
	}


	public void setHashAlgorithmName(String hashAlgorithmName) {
		this.hashAlgorithmName = hashAlgorithmName;
	}

	public int getHashIterations() {
		return hashIterations;
	}


	public void setHashIterations(int hashIterations) {
		this.hashIterations = hashIterations;
	}
	
	/**
	 * 获取一个新的加密密码
	 * @param username	用户登录名
	 * @param password	用户的名文密码
	 * @return Map   
	 * key :  MAP_KEY_USERNAME(用户名)  
	 *        MAP_KEY_PASSWORD(名文密码)
	 *        MAP_KEY_SALT    (加密盐)
	 *        MAP_KEY_NEWPWD  (加密后的密码)
	 */
	public Map<String, Object> newPassword(String username,
			char[] password) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(MAP_KEY_USERNAME, username);
		map.put(MAP_KEY_PASSWORD, password);
		map.put(MAP_KEY_SALT, null);
		SimpleHash hash = new SimpleHash(hashAlgorithmName, password);
		map.put(MAP_KEY_NEWPWD, hash.toHex());
		return map;
	}	
	
}
